#include<bits/stdc++.h>
using namespace std;
# define y1 yy

int n;
int fn[2][107][12][31];
const int days[2][12] = {
	{31,28,31,30,31,30,31,31,30,31,30,31},
	{31,29,31,30,31,30,31,31,30,31,30,31},
};
int getR(int y){
	return (y%400==0)||(y%4==0&&y%100!=0);
}
inline vector<int> getNexDate(int y,int mon,int d){
	int y1=y, m1=mon, d1 = d+1;
	if(d1>days[getR(y)][mon-1]){
		d1 = 1;
		m1++;
		if(m1>12){
			m1 = 1;
			y1 = y+1;
		}
	}
	return {y1,m1,d1};
}
inline vector<int> getNexMon(int y,int mon,int d){
	int y1=y, m1 = mon+1, d1 = d;
	if(m1>12){
		m1 = 1;
		y1 = y+1;
	}
	return {y1,m1,d1};
}

//2006.11.4
int dfs(bool ok,int y,int mon,int d){
	if(y==2006&&mon==11&&d==4){
		return ok?0:1;
	}
	if(y>2006||y==2006&&mon>11||y==2006&&mon==11&&d>4){
		return ok;
	}
	if(fn[ok][y-1900][mon-1][d-1]!=-1){
		return fn[ok][y-1900][mon-1][d-1];
	} 
	int y1,m1,d1;
	if(ok){
		//next date
		auto vec = getNexDate(y,mon,d);
		y1 = vec[0];
		m1 = vec[1];
		d1 = vec[2];
		if(dfs(!ok,y1,m1,d1)) return fn[ok][y-1900][mon-1][d-1] = 1;
		
		// next month
		vec = getNexMon(y,mon,d);
		y1 = vec[0];
		m1 = vec[1];
		d1 = vec[2];
		if(d1<=days[getR(y1)][m1-1]){
			if(dfs(!ok,y1,m1,d1)) return fn[ok][y-1900][mon-1][d-1] = 1;
		}
		return fn[ok][y-1900][mon-1][d-1] = 0;
	}
	else{
		// next date
		auto vec = getNexDate(y,mon,d);
		y1 = vec[0];  m1 = vec[1];  d1 = vec[2];
		if(!dfs(!ok,y1,m1,d1)) return fn[ok][y-1900][mon-1][d-1] = 0;
		
		//next mon
		vec = getNexMon(y,mon,d);
		y1 = vec[0]; m1 = vec[1]; d1 = vec[2];
		if(d1<=days[getR(y1)][m1-1]){
			if(!dfs(!ok,y1,m1,d1)) return fn[ok][y-1900][mon-1][d-1] = 0;
		}
		return fn[ok][y-1900][mon-1][d-1] = 1;
	}
}
int main(){
	scanf("%d",&n);
	memset(fn,0xff,sizeof(fn));
	while(n--){
		int y,mon,d;
		scanf("%d%d%d",&y,&mon,&d);
		bool res = dfs(1,y,mon,d);
		if(res) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
